AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / user-15283041

Victor Nielsen's questions

Martin Hope
Victor Nielsen
Asked: 2023-08-22 02:07:57 +0800 CST

A integração sobre uma função min () fornece um resultado diferente da função interna

  • 7

Esses dois resultados não deveriam ser iguais? Por que eles não são?

integrate(\(x) {x * min(-x+10, 10)},lower = 0, upper = 10)$value
> [1] 1.085709

integrate(\(x) {x * (-x+10)},lower = 0, upper = 10)$value
> [1] 166.6667

Tenha em mente que dos valores de x de 0 a 10 nunca devemos esperar obter um valor de y = -x + 10 que seja maior que 10, então min(-x+10, 10) sempre retornará (-x+10 ) desde que estejamos entre 0 e 10. Portanto, as duas integrais devem ser idênticas.

Por que eles não são?

  • 2 respostas
  • 22 Views
Martin Hope
Victor Nielsen
Asked: 2023-08-18 23:42:09 +0800 CST

Plotly começa na etapa errada do controle deslizante, mesmo depois de especificar

  • 5

Eu tenho o código abaixo, e o problema é que o controle deslizante não começa na posição do meio - ele começa na posição 4/5 em vez de t=650600. O gráfico mostrado na imagem é corretamente o da posição do meio ( t=600). Enquanto isso, o título aparece em t=700, mas vamos ignorá-lo por enquanto, a menos que você saiba por quê.

library(plotly)

x <- seq(0, 50, by = 0.1)
t_values <- seq(500, 700, by = 50)  # Adjusted t values

# Fixed y-axis range
y_range <- c(0, get_density(0, inc, 700, get_u(inc, 700, target_population)))  # Adjust this to your desired y-axis range

# create steps and plot all traces
steps <- list()
fig <- plot_ly()

aval <- list()
slider_steps <- list()

initial_slider_value <- 600  # Initial slider value

for (i in 1:length(t_values)) {
  t_value <- t_values[i]
  # Update u value based on the current t value
  u <- get_u(inc, t_value, target_population)

  # Update the border and population based on the new u value
  border_value <- get_border(target_border, inc, t_value, u)
  population_value <- get_population(inc, t_value, u)

  # Update the title to include the current t_value
  title_text <- paste("Transport cost:", t_value)

  aval[[i]] <- list(visible = t_value == initial_slider_value,  # Show line for the initial slider value
                    name = paste0('v = ', t_value),
                    x = x,
                    y = get_density(x, inc, t_value, u))

  fig <- add_lines(fig, x = aval[i][[1]]$x, y = aval[i][[1]]$y, visible = aval[i][[1]]$visible,
                   name = aval[i][[1]]$name, type = 'scatter', mode = 'lines', hoverinfo = 'name',
                   line = list(color = '00CED1'), showlegend = FALSE)

  step <- list(args = list('visible', rep(FALSE, length(aval))),
               method = 'restyle')
  step$args[[2]][i] = TRUE
  steps[[i]] = step

  # Define the slider step
  slider_steps[[i]] <- list(
    label = t_value,
    method = 'restyle',
    args = list('visible', rep(FALSE, length(t_values)))
  )
  slider_steps[[i]]$args[[2]][i] = TRUE
}

# Find the index of the initial slider value
initial_slider_index <- which(t_values == initial_slider_value)

# add slider control to plot
fig <- fig %>%
  layout(sliders = list(
    list(currentvalue = list(prefix = "Transport cost: "),
         steps = slider_steps,
         active = initial_slider_index  # Set the initial active slider
    )
  ),
  title = title_text,  # Set the initial title
  yaxis = list(range = y_range),  # Set fixed y-axis range
  xaxis = list(range = c(0, 50))  # Set the desired x-axis range
  )

fig

Por isso, especifiquei especificamente que quero que comece na marca 600 (no meio).

Imagem

Se você quiser testar o código, adicione isto acima:

alpha = 0.86 # Expenditure share on all other goods
beta = 0.6 # Cost share of housing capital in housing production function
g = 0.0005 # Scaling on housing production function
theta = 3 # Radians available for construction (benchmark is 3)
target_population <- 2000000
target_border <- 40
inc <- 70000
t <- 600
ra <- 45000
u <- 5353.65
x <- 0

get_price <- function(x,inc,t,u) {
  (((alpha^alpha) * ((1 - alpha)^(1 - alpha)) * (inc - t * x)) / u)^(1 / (1 - alpha))
}

get_quantity <- function(x,inc,t,u) {
  (((1 - alpha) * (inc - t * x)) / (((alpha^alpha) * ((1 - alpha)^(1 - alpha)) * (inc - t * x)) / u)^(1 / (1 - alpha)))
}

get_capital_intensitinc <- function(x,inc,t,u) {
  (1 / (get_price(x,inc,t,u) * (beta) * (g)))^(1 / (beta - 1))
}

get_rent <- function(x,inc,t,u) {
  (get_price(x,inc,t,u) * (g)) * ((1/(get_price(x,inc,t,u) * (beta) * (g)))^(beta / (beta - 1))) - 1 * ((1 / (get_price(x,inc,t,u) * (beta) * (g)))^(1 / (beta - 1)))
}

get_far <- function(x,inc,t,u) {
  (g) * get_capital_intensitinc(x,inc,t,u)^(beta)
}

get_density <- function(x,inc,t,u) {
  get_far(x,inc,t,u) / get_quantity(x,inc,t,u)
}

get_border <- function(target_border,inc,t,u) {
  uniroot(\(x) get_rent(x,inc,t,u) - ra, lower = 0, upper = 100)$root
}

get_population <- function(inc,t,u) {
  theta * integrate(\(x) {x * get_density(x,inc,t,u)},lower = 0, upper = get_border(target_border,inc,t,u))$value
}

get_u <- function(inc,t,target_population) {
  uniroot(\(u) get_population(inc,t,u) - target_population, c(4500, 6500))$root
}

u <- get_u(inc,t,target_population)
  • 1 respostas
  • 14 Views

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Reformatar números, inserindo separadores em posições fixas

    • 6 respostas
  • Marko Smith

    Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não?

    • 2 respostas
  • Marko Smith

    Problema com extensão desinstalada automaticamente do VScode (tema Material)

    • 2 respostas
  • Marko Smith

    Vue 3: Erro na criação "Identificador esperado, mas encontrado 'import'" [duplicado]

    • 1 respostas
  • Marko Smith

    Qual é o propósito de `enum class` com um tipo subjacente especificado, mas sem enumeradores?

    • 1 respostas
  • Marko Smith

    Como faço para corrigir um erro MODULE_NOT_FOUND para um módulo que não importei manualmente?

    • 6 respostas
  • Marko Smith

    `(expression, lvalue) = rvalue` é uma atribuição válida em C ou C++? Por que alguns compiladores aceitam/rejeitam isso?

    • 3 respostas
  • Marko Smith

    Um programa vazio que não faz nada em C++ precisa de um heap de 204 KB, mas não em C

    • 1 respostas
  • Marko Smith

    PowerBI atualmente quebrado com BigQuery: problema de driver Simba com atualização do Windows

    • 2 respostas
  • Marko Smith

    AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos

    • 1 respostas
  • Martin Hope
    Fantastic Mr Fox Somente o tipo copiável não é aceito na implementação std::vector do MSVC 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant Encontre o próximo dia da semana usando o cronógrafo 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor O inicializador de membro do construtor pode incluir a inicialização de outro membro? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul O C++20 mudou para permitir a conversão de `type(&)[N]` de matriz de limites conhecidos para `type(&)[]` de matriz de limites desconhecidos? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann Como/por que {2,3,10} e {x,3,10} com x=2 são ordenados de forma diferente? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller O ponto e vírgula agora é opcional em condicionais bash com [[ .. ]] na versão 5.2? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench Por que um traço duplo (--) faz com que esta cláusula MariaDB seja avaliada como verdadeira? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng Por que `dict(id=1, **{'id': 2})` às vezes gera `KeyError: 'id'` em vez de um TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos 2024-03-20 03:12:31 +0800 CST

Hot tag

python javascript c++ c# java typescript sql reactjs html

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve