I have this basic function: zyskkranc=100 kosztramienia=500 boxes2=boxes*zyskkranc…
- User
I have this basic function: zysk_kranc=100 koszt_ramienia=500 boxes2=boxeszysk_kranc c_storage2=c_storagekoszt_ramienia profit=Vector() for i in 1:length(boxes2) zysk=boxes2[i]-boxes2[1]-c_storage2[i] print(zysk) push!(profit,zysk)
endmax_profit, max_index = findmax(profit)
Now I want to show how the changes of variables : zysk_kranc and koszt_ramienia influence optimal value of c_storage and profit on plot.
- Assistant
To visualize the changes in zysk_kranc and koszt_ramienia on the optimal value of c_storage and profit, you can create a 3D plot using the Plots library in Julia. Here's how you can modify your code:
julia - User
So I have rewritten this to this: using Plots
zysk_kranc = 50:10:150 koszt_ramienia = 400:25:600
profit_matrix = Array{Float64}(undef, length(zysk_kranc), length(koszt_ramienia)) c_storage_optimal = Array{Float64}(undef, length(zysk_kranc), length(koszt_ramienia))
for (i, zysk) in enumerate(zysk_kranc) for (j, koszt_ramienia) in enumerate(koszt_ramienia) boxes2 = boxes * zysk c_storage2 = c_storage * koszt_ramienia profit = Vector()
codefor k in 1:length(boxes2) zysk = boxes2[k] - boxes2[1] - c_storage2[k] push!(profit, zysk) end max_profit, max_index = findmax(profit) profit_matrix[i, j] = max_profit c_storage_optimal[i, j] = c_storage[max_index] endend
surface(zysk_kranc, koszt_ramienia, profit_matrix, xlabel="zysk", ylabel="koszt_ramienia", zlabel="Profit") surface!(zysk_kranc, koszt_ramienia, c_storage_optimal, xlabel="zysk", ylabel="koszt_ramienia", zlabel="Optimal c_storage")
and I am getting error : Arrays have incorrect length or dimension. Arrays have incorrect length or dimension. Fix it
- Assistant
Apologies for the confusion. It seems the error is caused by the reassignment of the variable
zyskwithin the loop. I have revised the loop variable names to avoid such clashes, which should resolve the error.julia